Skip to content

feat: add retry mechanism to auto_loop click steps#55

Open
peach322 wants to merge 1 commit intoAliceJump:masterfrom
peach322:copilot/add-retry-mechanism-for-clicks
Open

feat: add retry mechanism to auto_loop click steps#55
peach322 wants to merge 1 commit intoAliceJump:masterfrom
peach322:copilot/add-retry-mechanism-for-clicks

Conversation

@peach322
Copy link
Copy Markdown

@peach322 peach322 commented Apr 27, 2026

Agent-Logs-Url: https://github.com/peach322/ok-gf2/sessions/99d7e04a-75ea-4c08-936a-2cd3e1c0106e

Summary by CodeRabbit

Release Notes

  • New Features

    • Added automatic retry mechanism for autonomous loop steps with failure detection, allowing up to 3 attempts to ensure successful execution with timeout verification.
  • Bug Fixes

    • Enhanced task execution reliability through improved sequential step processing and verification logic.

Agent-Logs-Url: https://github.com/peach322/ok-gf2/sessions/99d7e04a-75ea-4c08-936a-2cd3e1c0106e

Co-authored-by: peach322 <268908037+peach322@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

The changes add retry-capable logic to the DailyTask auto loop feature. A new helper method handles verifying OCR-based clicks with up to 3 retry attempts, checking if clicked features disappear within a 3-second window. The auto_loop() method is refactored to explicitly sequence steps using this helper instead of lambda-based lists.

Changes

Cohort / File(s) Summary
Auto Loop Retry Logic
src/tasks/DailyTask.py
Added _auto_loop_step_with_retry() helper method that verifies OCR click success by advancing frames and re-running OCR verification, with up to 3 retry attempts before logging failure. Refactored auto_loop() to replace lambda-based step list with explicit sequential execution using the new helper for steps 1–3 and 5, while step 4 remains a one-shot click check with early exit on failure.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit hops through loops so fine,
Click-verify, retry in time!
Three chances dance in OCR's gaze,
Steps march forward through the maze,
No more lambdas cluttering sight,
Sequential steps burning bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a retry mechanism to auto_loop click steps, which is the primary functionality introduced in the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/tasks/DailyTask.py (1)

508-513: Scope "确认" OCR to a stable region to avoid false retries.

Step 3 and step 5 use match=["确认"] without box. The disappearance check then scans the full screen, so unrelated "确认" text can keep triggering retries/failure.

🔧 Proposed refactor
     def auto_loop(self):
+        confirm_box = self.box.bottom_right  # adjust to the actual confirm area if needed
+
         # 步骤 1: 点击"自主循环",带重试
         if not self._auto_loop_step_with_retry(
             step_num=1,
             match=[re.compile("自主循环")],
             box=self.box.bottom_left,
@@
         if not self._auto_loop_step_with_retry(
             step_num=3,
             match=["确认"],
+            box=confirm_box,
             settle_time=2,
             after_sleep=2,
         ):
             return
@@
         if not self._auto_loop_step_with_retry(
             step_num=5,
             match=["确认"],
+            box=confirm_box,
             settle_time=2,
             after_sleep=2,
         ):
             return

Also applies to: 524-529

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tasks/DailyTask.py` around lines 508 - 513, The OCR match for "确认" in
calls to _auto_loop_step_with_retry (used for step_num=3 and the similar call
around step_num=5) currently scans the full screen and can pick up unrelated
"确认" text; update both calls to pass a stable box parameter (pixel or normalized
rect) that confines OCR to the dialog/button area where the confirmation
appears, e.g. add box=<appropriate_rect> to the _auto_loop_step_with_retry
invocation so disappearance checking only scans that region and avoids false
retries/failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/tasks/DailyTask.py`:
- Around line 462-464: The added Chinese docstrings/comments in
src/tasks/DailyTask.py use fullwidth punctuation (e.g., fullwidth
commas/periods/quotes) which triggers Ruff confusable-character warnings
(RUF001/RUF002/RUF003); fix by normalizing those punctuation characters to ASCII
equivalents in the affected docstrings/comments (the docstring block around the
OCR click behavior and the subsequent comment blocks you added) or, if localized
fullwidth punctuation is intentional, append a per-line or per-block Ruff noqa
comment (e.g., # noqa: RUF001,RUF002,RUF003) to those specific
docstrings/comments so Ruff stops flagging them. Ensure you update the same text
blocks mentioned in the review (the OCR/docstring and the other nearby comment
blocks) rather than changing unrelated code.
- Around line 466-473: The retry loop currently returns immediately on the first
falsy result from wait_click_ocr, skipping remaining attempts; change the logic
in the loop that iterates "for attempt in range(3)" so that when
wait_click_ocr(...) returns falsy you log the attempt failure (using
self.log_info and step_num) and continue to the next iteration instead of
returning False, and after the loop completes (if all attempts fail) return
False once—this preserves retries for transient OCR misses while keeping the
final failure behavior.

---

Nitpick comments:
In `@src/tasks/DailyTask.py`:
- Around line 508-513: The OCR match for "确认" in calls to
_auto_loop_step_with_retry (used for step_num=3 and the similar call around
step_num=5) currently scans the full screen and can pick up unrelated "确认" text;
update both calls to pass a stable box parameter (pixel or normalized rect) that
confines OCR to the dialog/button area where the confirmation appears, e.g. add
box=<appropriate_rect> to the _auto_loop_step_with_retry invocation so
disappearance checking only scans that region and avoids false retries/failures.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3054bc37-70ac-4e2e-9b83-80d31412a3ea

📥 Commits

Reviewing files that changed from the base of the PR and between abed4ea and 508de20.

📒 Files selected for processing (1)
  • src/tasks/DailyTask.py

Comment thread src/tasks/DailyTask.py
Comment on lines +462 to +464
"""
点击OCR匹配元素,等待点击特征在 3s 内消失。
若特征未消失则重试,最多尝试 3 次。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Ruff confusable-character warnings are present in newly added text.

The new docstrings/comments/strings contain fullwidth punctuation flagged by Ruff (RUF001/RUF002/RUF003). If lint is gating, normalize punctuation or add an explicit rule exception for localized Chinese text.

Also applies to: 471-473, 482-483, 487-497, 507-523

🧰 Tools
🪛 Ruff (0.15.12)

[warning] 463-463: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF002)


[warning] 464-464: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF002)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tasks/DailyTask.py` around lines 462 - 464, The added Chinese
docstrings/comments in src/tasks/DailyTask.py use fullwidth punctuation (e.g.,
fullwidth commas/periods/quotes) which triggers Ruff confusable-character
warnings (RUF001/RUF002/RUF003); fix by normalizing those punctuation characters
to ASCII equivalents in the affected docstrings/comments (the docstring block
around the OCR click behavior and the subsequent comment blocks you added) or,
if localized fullwidth punctuation is intentional, append a per-line or
per-block Ruff noqa comment (e.g., # noqa: RUF001,RUF002,RUF003) to those
specific docstrings/comments so Ruff stops flagging them. Ensure you update the
same text blocks mentioned in the review (the OCR/docstring and the other nearby
comment blocks) rather than changing unrelated code.

Comment thread src/tasks/DailyTask.py
Comment on lines +466 to +473
for attempt in range(3):
result = self.wait_click_ocr(
match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs
)
if not result:
self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
return False
# 等待最多 3s,检测点击特征是否消失
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Retry loop exits on first OCR miss, so retries are skipped.

When wait_click_ocr returns falsy, the function returns immediately instead of trying remaining attempts. This bypasses retry behavior for transient OCR misses.

🔧 Proposed fix
         for attempt in range(3):
             result = self.wait_click_ocr(
                 match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs
             )
             if not result:
-                self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
-                return False
+                if attempt < 2:
+                    self.log_info(
+                        f"自主循环步骤{step_num}未识别到目标,重试 ({attempt + 2}/3)",
+                        notify=True
+                    )
+                    continue
+                self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
+                return False
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for attempt in range(3):
result = self.wait_click_ocr(
match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs
)
if not result:
self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
return False
# 等待最多 3s,检测点击特征是否消失
for attempt in range(3):
result = self.wait_click_ocr(
match=match, box=box, time_out=time_out, after_sleep=0, log=True, **kwargs
)
if not result:
if attempt < 2:
self.log_info(
f"自主循环步骤{step_num}未识别到目标,重试 ({attempt + 2}/3)",
notify=True
)
continue
self.log_info(f"自主循环步骤{step_num}未完成,退出循环", notify=True)
return False
# 等待最多 3s,检测点击特征是否消失
🧰 Tools
🪛 Ruff (0.15.12)

[warning] 471-471: String contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF001)


[warning] 473-473: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tasks/DailyTask.py` around lines 466 - 473, The retry loop currently
returns immediately on the first falsy result from wait_click_ocr, skipping
remaining attempts; change the logic in the loop that iterates "for attempt in
range(3)" so that when wait_click_ocr(...) returns falsy you log the attempt
failure (using self.log_info and step_num) and continue to the next iteration
instead of returning False, and after the loop completes (if all attempts fail)
return False once—this preserves retries for transient OCR misses while keeping
the final failure behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants